//
//  DoubleBallDrawing+Validation.m
//  MySwift
//
//  Created by 周杨 on 14/11/2.
//  Copyright (c) 2014年 zhouy. All rights reserved.
//

#import "DoubleBallDrawing+Validation.h"
#import "DoubleTicket.h"
#import "DoubleColorBall.h"

@implementation DoubleBallDrawing (Validation)



//
//判断是否与历史中奖号码重复
//
-(BOOL) isHistory:(DoubleTicket *) myTicket{
    
//    NSLog(@"  历x史验证执行！");
    
    NSString * fileUrl =@"/Users/zhouyang/程序/MySwift/FoodHub/FoodHub/TicketBall/Temp.strings";
    NSString * string = [NSString stringWithContentsOfFile:fileUrl encoding:NSUTF8StringEncoding error:nil];
    NSArray * lineArr = [string componentsSeparatedByString:@"\n"];
    
    //读取每一行并构造为ticketBall对象
    for (NSString * line in lineArr) {
        NSArray * dataArr =[line componentsSeparatedByString:@"\t"];
        NSMutableArray * dataTicketArr = [[NSMutableArray alloc] init];
        DoubleTicket * ticket =[[DoubleTicket alloc] init];
        
        for (int i=0,size=(int)[dataArr count]; i<size; i++ ) {
            if(i>=1&& i<=6){
                [dataTicketArr addObject:[[DoubleColorBall alloc] init:@"Red" andNo:(int)[dataArr objectAtIndex:i] ]];
            }
            else if(i==7){
                
                [dataTicketArr addObject:[[DoubleColorBall alloc] init:@"Blue" andNo:(int)[dataArr objectAtIndex:i] ]];
            }
            
            continue;
        }
        
        [ticket setReBallArry:dataTicketArr];
        
        //验证是否为重复号码
        if([[myTicket ticketSortStr] isEqualToString:[ticket ticketSortStr]]){
            return true;
        }
    }
    
    return false;
}
@end
